using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using System;
using yW5Lib;

namespace yWriter6
{
	[StandardModule]
	internal sealed class modGenerateProject
	{
		public static bool GenerateProject(ref clsProject cProject, string OutlineText)
		{
			//Discarded unreachable code: IL_0299, IL_02b0, IL_02bb, IL_02cb, IL_0381, IL_0383, IL_0397, IL_03b9
			int num = default(int);
			bool result = false;
			int num6 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				if (cProject.ChapterCount <= 0)
				{
					goto IL_0060;
				}
				num2 = 3;
				int num3 = (int)clsShared.cLang.TransMsgBox("Do you want to clear everything from the current project first? (If you say No the new chapters and scenes will be added to the end.)", MsgBoxStyle.YesNoCancel);
				num2 = 4;
				if (num3 == 6)
				{
					num2 = 5;
					if (clsShared.cLang.TransMsgBox("WARNING! About to erase all data from this project. Are you sure?", MsgBoxStyle.YesNo) == MsgBoxResult.Yes)
					{
						num2 = 6;
						cProject.Clear(FilenameToo: true);
					}
					goto IL_0060;
				}
				num2 = 8;
				if (num3 != 2)
				{
					goto IL_0060;
				}
				num2 = 9;
				result = false;
				goto end_IL_0000;
				IL_0060:
				num2 = 11;
				clsShared.cSubs.BusyMouse();
				num2 = 12;
				string[] array = Strings.Split(OutlineText, "[chapter]");
				num2 = 13;
				num2 = 14;
				if (cProject.CharCount == 0)
				{
					num2 = 15;
					clsCharacter cChr = new clsCharacter();
					num2 = 16;
					cChr.Title = "Character";
					num2 = 17;
					cProject.AddChar(ref cChr);
				}
				num2 = 18;
				int num4 = Information.UBound(array);
				for (int i = 1; i <= num4; i++)
				{
					num2 = 19;
					string[] array2 = Strings.Split(array[i], "[scene]");
					num2 = 20;
					clsChapter cChapter = new clsChapter();
					num2 = 21;
					cChapter.Title = Strings.Trim(Strings.Replace(Strings.Replace(array2[0], "\r", ""), "\n", ""));
					num2 = 22;
					cProject.AddChapter(ref cChapter);
					num2 = 23;
					int num5 = Information.UBound(array2);
					for (int j = 1; j <= num5; j++)
					{
						num2 = 24;
						clsScene Scene = new clsScene();
						num2 = 25;
						Scene.V6 = cProject.V6File;
						num2 = 26;
						string[] array3;
						if ((Strings.InStr(array2[j], ".") != 0) & (Strings.InStr(array2[j], ".") < Strings.InStr(array2[j], "\r\n")))
						{
							num2 = 27;
							array3 = Strings.Split(array2[j], ".", 2);
						}
						else
						{
							num2 = 29;
							array3 = Strings.Split(array2[j], "\r\n", 2);
						}
						num2 = 30;
						if (Information.UBound(array3) > 0)
						{
							num2 = 31;
							Scene.Title = Strings.Trim(Strings.Replace(Strings.Replace(array3[0], "\r", ""), "\n", ""));
							num2 = 32;
							Scene.DescText = Strings.Trim(Strings.Replace(Strings.Replace(array3[1], "\r", ""), "\n", ""));
							num2 = 33;
							Scene.SetViewpointByID(1);
							num2 = 34;
							cProject.AddSceneToProjectAndChapter(ref Scene, cChapter.ID);
						}
						num2 = 35;
					}
					num2 = 36;
				}
				num2 = 37;
				result = true;
				num2 = 38;
				clsShared.cSubs.NormalMouse();
				end_IL_0000:;
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num6 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_03b7: Could not find block for branch target IL_0383*/;
			}
			if (num6 != 0)
			{
				ProjectData.ClearProjectError();
			}
			return result;
		}
	}
}
